package com.isloop;

import java.io.PrintWriter;
import javax.servlet.jsp.JspWriter;

public class Message{
	JspWriter out= null;
	PrintWriter sout=null;
	
	String SystemName="ChinaMobile Company of CangZhou";
	String SystemVersion="V 1.0";
	
	String CopyRight=SystemName+" "+ SystemVersion;
	boolean IsServlet=false;
	public Message(JspWriter out){
		this.out=out;
		IsServlet=false;
	}
	public Message(PrintWriter sout){
		this.sout=sout;
		IsServlet=true;
	}
	private String FormartStr(String Str){
		if (Str == null || Str.equals("")){ 
			return ""; 
		}
		if(IsServlet){
			try{
				Str=new String(Str.getBytes(),"ISO-8859-1");
			}
			catch(Exception e){
				
			}
		}
		Str=Str.replaceAll("'", "\\'");
		Str=Str.replaceAll("\"", "\\\"");
		Str=Str.replaceAll("\r", "\\\n");
		return Str;
	}
	private void OutInfo(String Info){
		try{
			if(this.IsServlet){
				sout.println(Info);
			}
			else{
				out.println(Info);
			}
		}
		catch(Exception e){
			com.isloop.SysError.RecordErr(this.toString(),e.getMessage());
		}
	}
	public void Show(String Info){
		Info="<script language=\"javascript\">alert(\""+ 
				this.FormartStr(Info) +"\\n\\n "+ CopyRight +"\");</script>";
		this.OutInfo(Info);
	}
	public void Go(String Info,String Url){
		Info="<script language=\"javascript\">alert(\""+ 
				this.FormartStr(Info) +"\\n\\n "+ CopyRight +"\");window.location=\""+ Url +"\";</script>";
		this.OutInfo(Info);
	}
	public void Go(String Info,String Url,String Target){
		Info="<script language=\"javascript\">alert(\""+ 
				this.FormartStr(Info) +"\\n\\n "+ CopyRight +"\");"+ Target +".location=\""+ Url +"\";</script>";		
		this.OutInfo(Info);
	}
	public void Back(String Info){
		Info="<script language=\"javascript\">alert(\""+ 
				this.FormartStr(Info) +"\\n\\n "+ CopyRight +"\");window.history.back();</script>";
		this.OutInfo(Info);
	}
	public void CloseReturn(String Info,String Return){
		Info="<script language=\"javascript\">alert(\""+ 
				this.FormartStr(Info) +"\\n\\n "+ CopyRight +"\");parent.returnValue='"+ Return +"';parent.close();</script>";
		this.OutInfo(Info);
	}
}